]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
[search] Finish queued search on Return
authorColin Walters <walters@verbum.org>
Tue, 13 Oct 2009 18:18:47 +0000 (14:18 -0400)
committerColin Walters <walters@verbum.org>
Tue, 13 Oct 2009 20:57:39 +0000 (16:57 -0400)
If we had a pending search processing, finish it when the user
activates the entry.

This is a small conceptual change; the large diff is simply
moving the search implementation (unedited otherwise) from
an anonymous inline to a named function so it can be called
sanely in _activate.

https://bugzilla.gnome.org/show_bug.cgi?id=598111

js/ui/dash.js

index 28cd700652722f6f975d7d92b4dc91d944acf877..2f367753ab0467eb68c2f5142d25f97cba2c03a9 100644 (file)
@@ -641,51 +641,13 @@ Dash.prototype = {
             }
             if (this._searchTimeoutId > 0)
                 return;
-            this._searchTimeoutId = Mainloop.timeout_add(150, Lang.bind(this, function() {
-                this._searchTimeoutId = 0;
-                let text = this._searchEntry.getText();
-                text = text.replace(/^\s+/g, "").replace(/\s+$/g, "");
-
-                let selectionSet = false;
-
-                for (var i = 0; i < this._searchSections.length; i++) {
-                    let section = this._searchSections[i];
-                    section.resultArea.display.setSearch(text);
-                    let itemCount = section.resultArea.display.getMatchedItemsCount();
-                    let itemCountText = itemCount + "";
-                    section.header.countText.text = itemCountText;
-
-                    if (this._searchResultsSingleShownSection == section.type) {
-                        this._searchResultsSection.header.setCountText(itemCountText);
-                        if (itemCount == 0) {
-                            section.resultArea.actor.hide();
-                        } else {
-                            section.resultArea.actor.show();
-                        }
-                    } else if (this._searchResultsSingleShownSection == null) {
-                        // Don't show the section if it has no results
-                        if (itemCount == 0) {
-                            section.header.actor.hide();
-                            section.resultArea.actor.hide();
-                        } else {
-                            section.header.actor.show();
-                            section.resultArea.actor.show();
-                        }
-                    }
-
-                    // Refresh the selection when a new search is applied.
-                    section.resultArea.display.unsetSelected();
-                    if (!selectionSet && section.resultArea.display.hasItems() &&
-                        (this._searchResultsSingleShownSection == null || this._searchResultsSingleShownSection == section.type)) {
-                        section.resultArea.display.selectFirstItem();
-                        selectionSet = true;
-                    }
-                }
-
-                return false;
-            }));
+            this._searchTimeoutId = Mainloop.timeout_add(150, Lang.bind(this, this._doSearch));
         }));
         this._searchEntry.entry.connect('activate', Lang.bind(this, function (se) {
+            if (this._searchTimeoutId > 0) {
+                Mainloop.source_remove(this._searchTimeoutId);
+                this._doSearch();
+            }
             // Only one of the displays will have an item selected, so it's ok to
             // call activateSelected() on all of them.
             for (var i = 0; i < this._searchSections.length; i++) {
@@ -856,6 +818,50 @@ Dash.prototype = {
         this._searchResultsSection.actor.hide();
     },
 
+    _doSearch: function () {
+        this._searchTimeoutId = 0;
+        let text = this._searchEntry.getText();
+        text = text.replace(/^\s+/g, "").replace(/\s+$/g, "");
+
+        let selectionSet = false;
+
+        for (var i = 0; i < this._searchSections.length; i++) {
+            let section = this._searchSections[i];
+            section.resultArea.display.setSearch(text);
+            let itemCount = section.resultArea.display.getMatchedItemsCount();
+            let itemCountText = itemCount + "";
+            section.header.countText.text = itemCountText;
+
+            if (this._searchResultsSingleShownSection == section.type) {
+                this._searchResultsSection.header.setCountText(itemCountText);
+                if (itemCount == 0) {
+                    section.resultArea.actor.hide();
+                } else {
+                    section.resultArea.actor.show();
+                }
+            } else if (this._searchResultsSingleShownSection == null) {
+                // Don't show the section if it has no results
+                if (itemCount == 0) {
+                    section.header.actor.hide();
+                    section.resultArea.actor.hide();
+                } else {
+                    section.header.actor.show();
+                    section.resultArea.actor.show();
+                }
+            }
+
+            // Refresh the selection when a new search is applied.
+            section.resultArea.display.unsetSelected();
+            if (!selectionSet && section.resultArea.display.hasItems() &&
+                (this._searchResultsSingleShownSection == null || this._searchResultsSingleShownSection == section.type)) {
+                section.resultArea.display.selectFirstItem();
+                selectionSet = true;
+            }
+        }
+
+        return false;
+    },
+
     show: function() {
         global.stage.set_key_focus(this._searchEntry.entry);
     },